package com.shandao.shangxiu.util;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.shandao.shangxiu.AppContext;
import com.shandao.shangxiu.R;
import com.ta.utdid2.android.utils.StringUtils;



/**
 * toast类
 */
public class ToastUtils {
    private static Toast mToast = null;

    public static void show(final String message) {
        if(StringUtils.isEmpty(message)){
            return;
        }
        if (mToast == null) {
            View view = LayoutInflater.from(AppContext.getInstance()).inflate(R.layout.toast, null);
            mToast = new Toast(AppContext.getInstance());
            mToast.setGravity(Gravity.CENTER, 0, 0);
            mToast.setDuration(Toast.LENGTH_SHORT);
            mToast.setView(view);
        }
        TextView textView = (TextView) mToast.getView().findViewById(
                R.id.toast_text);
        textView.setText(message);
        mToast.show();
    }

    public static void show(int resId) {
        show(AppContext.getInstance().getString(resId));
    }

    public static void cancel() {
        if (mToast != null) {
            mToast.cancel();
        }
    }
}
